﻿Imports System.IO
Imports System.Runtime.CompilerServices
Imports System.Runtime.Serialization.Formatters.Binary

<Extension()> _
Module SerializationHelper
    <Extension()> _
  Public Sub Serialize(Of T As New)(ByVal type As T, ByVal stream As Stream)
        Dim formatter As New BinaryFormatter()
        formatter.Serialize(stream, type)
    End Sub

    <Extension()> _
    Public Function Deserialize(Of T As New)(ByVal stream As Stream) As T
        Return DirectCast(New BinaryFormatter().Deserialize(stream), T)
    End Function
End Module
